Skip to content

fix: gate feature-injection kwargs on TensorRT backend in SD1.5/2.1 UNet call#13

Merged
forkni merged 1 commit into
SDTD_032_devfrom
integ/fio-cache-gate-to-032
Jul 19, 2026
Merged

fix: gate feature-injection kwargs on TensorRT backend in SD1.5/2.1 UNet call#13
forkni merged 1 commit into
SDTD_032_devfrom
integ/fio-cache-gate-to-032

Conversation

@forkni

@forkni forkni commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

Cherry-pick of the same fix landed on SDTD_040_beta_release in #12 (files were byte-identical pre-fix, so this is a clean, verbatim port).

  • Fixes a crash on every frame for non-TensorRT SD1.5/2.1 backends (acceleration: none/xformers/sfast): UNet2DConditionModel.forward() got an unexpected keyword argument 'fio_cache'.
  • Root cause: unet_step()'s SD1.5/2.1 branch unconditionally passed fio_cache/fi_strength/fi_threshold to self.unet(...), but those TensorRT-only feature-injection kwargs are not understood by the patched eager PyTorch UNet (_patches/diffusers_kvo_patch.py only adds kvo_cache). The SDXL branch already gated these correctly on _check_unet_tensorrt(); the SD1.5/2.1 branch did not.
  • Fix (Option B): always pass kvo_cache (supported on both backends via the import-time patch), but gate fio_cache/fi_strength/fi_threshold behind self._check_unet_tensorrt(), matching the SDXL branch's convention.

Test plan

  • New regression test tests/unit/test_unet_call_backend_gate.py, already verified green (3/3) plus a full 216/216 unit-suite pass against the identical pipeline.py on the 040 branch (fix: gate feature-injection kwargs on TensorRT backend in SD1.5/2.1 UNet call #12).
  • Diffed both changed files against the tested 040 versions post-cherry-pick: byte-identical.
  • Cherry-pick applied with zero conflicts (pre-fix files were byte-identical between branches).

🤖 Generated with Claude Code

…Net call (#12)

The SD1.5/2.1 branch of unet_step() unconditionally passed kvo_cache/fio_cache/
fi_strength/fi_threshold to self.unet(...). The import-time diffusers patch
(_patches/diffusers_kvo_patch.py) adds kvo_cache support to the eager PyTorch
UNet, but feature injection is TensorRT-engine-only — the patched forward()
has no fio_cache/fi_strength/fi_threshold parameters. Every non-TRT SD1.5/2.1
run (e.g. acceleration: none) crashed on the first call:

  UNet2DConditionModel.forward() got an unexpected keyword argument 'fio_cache'

Mirrors the SDXL branch's existing _check_unet_tensorrt() gate: kvo_cache is
always passed (both backends support it), the FI trio only when TRT is active.

Adds tests/unit/test_unet_call_backend_gate.py, which reproduces the crash via
a real (patched) tiny UNet2DConditionModel at the actual unet_step() call site
and locks in that the TensorRT path keeps receiving all four cache kwargs.
@claude

claude Bot commented Jul 19, 2026

Copy link
Copy Markdown

Claude finished @forkni's task in 1m 37s —— View job


Code review

  • Gather context (PR diff, CLAUDE.md files — none exist in this repo)
  • Run automated code review (bug scan, 2 parallel Opus agents)
  • Validate flagged issues
  • Post final review summary

No issues found. Checked for bugs and CLAUDE.md compliance (no CLAUDE.md exists in this repo).

Summary: This is a clean, verbatim cherry-pick of the already-reviewed/tested fix from #12.

  • src/streamdiffusion/pipeline.py (SD1.5/2.1 branch of unet_step(), lines ~1000–1018): kvo_cache is now always passed to self.unet(...) (supported by both TensorRT and the patched eager PyTorch UNet), while fio_cache/fi_strength/fi_threshold are gated behind self._check_unet_tensorrt() — exactly mirroring the pre-existing SDXL branch's convention (lines ~931–955). No key collisions with ip_scale_kw, no double-passing, attribute names match the SDXL branch exactly.
  • New regression test tests/unit/test_unet_call_backend_gate.py exercises both the non-TRT path (asserts fio_cache/fi_strength/fi_threshold are never sent to a non-TRT UNet) and the TRT path (asserts they still are), using a real tiny patched UNet2DConditionModel plus a fake TRT engine stand-in — solid coverage of the actual crash and a guard against regressing the TRT feature-injection path.
  • Confirmed the diff is scoped exactly as described (+12/-3 in pipeline.py, +181 new test file) with no unrelated changes.

No bugs, logic errors, or CLAUDE.md violations found.

@forkni
forkni merged commit 23d2f37 into SDTD_032_dev Jul 19, 2026
1 check passed
@forkni
forkni deleted the integ/fio-cache-gate-to-032 branch July 19, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant